home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 201-225 / 214 / mandelvroom / src / disp.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  21KB  |  1,038 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents:  this file contains the routines that open and close
  25.  * MandelVrooms custom screen as well as the required Amiga libraries.
  26.  *
  27.  */
  28.  
  29. #include "mandp.h"
  30.  
  31. char *ExecLib   = "exec.library";
  32. char *IntuiLib  = "intuition.library";
  33. char *GfxLib    = "graphics.library";
  34. char *LayersLib = "layers.library";
  35. char *FFPLib    = "mathffp.library";
  36. char *TransLib  = "mathtrans.library";
  37. char *IEEELib   = "mathieeedoubbas.library";
  38. char *IconLib   = "icon.library";
  39.  
  40. struct IntuitionBase       *IntuitionBase;
  41. struct GfxBase             *GfxBase;
  42. struct MathBase            *MathBase;
  43. struct MathTransBase       *MathTransBase;
  44. struct LayersBase          *LayersBase;
  45. struct ExecBase            *ExecBase;
  46. struct MathIeeeDoubBasBase *MathIeeeDoubBasBase;
  47. extern struct IconBase     *IconBase;
  48.  
  49. struct Screen   *screen;
  50. struct ViewPort *vp;
  51.  
  52. int Num_vp_Colors;
  53.  
  54. UBYTE StandardSize;
  55.  
  56. extern BYTE FromWB;
  57.  
  58. /*
  59.  * The following window's message port is used to communicate with
  60.  * all the other windows in the system.  It is a small backdrop,
  61.  * borderless window that is always open and in custom screen used
  62.  * by MandelVroom.
  63.  */
  64.  
  65. struct Window *BackWind;
  66.  
  67. struct NewWindow NewBack = {
  68.    0,10,                     /* start position           */
  69.    0,0,                      /* width, height            */
  70.    (UBYTE) 0, (UBYTE) 1,     /* detail pen, block pen    */
  71.                              /* IDCMP flags */
  72.    MENUPICK | GADGETDOWN | GADGETUP | REQCLEAR | CLOSEWINDOW |
  73.    MOUSEBUTTONS | ACTIVEWINDOW | NEWSIZE,
  74.    /* backWind flags */
  75.    ACTIVATE|BACKDROP|BORDERLESS|REPORTMOUSE|NOCAREREFRESH|SIMPLE_REFRESH,
  76.    (struct Gadget *) NULL,   /* first gadget             */
  77.    (struct Image *) NULL,    /* user checkmark           */
  78.    (UBYTE *) NULL,           /* Title                    */
  79.    (struct Screen *) NULL,   /* pointer to screen        */
  80.    (struct BitMap *) NULL,   /* pointer to superbitmap   */
  81.    8,8,-1,-1,                /* sizing                   */
  82.    CUSTOMSCREEN              /* type of screen           */
  83. };
  84.  
  85. extern struct Window *CurWind;
  86.  
  87. SHORT YScale, XScale;
  88.  
  89. static
  90. struct TextAttr myfont = {
  91.    (STRPTR) "topaz.font",
  92.    TOPAZ_EIGHTY,
  93.    0,
  94.    0
  95. };
  96.  
  97.  
  98. struct NewScreen NewScreen = {
  99.    0,0,                      /* start position           */
  100.    320, 200, 5,              /* width, height, depth     */
  101.    (UBYTE)  0, (UBYTE)  1,   /* detail pen, block pen    */
  102.    (USHORT) NULL,            /* HIRES, INTERLACE, SPRITES, DUAL, HAM */
  103.    CUSTOMSCREEN,             /* screen type              */
  104.    &myfont,                  /* font to use              */
  105.    (UBYTE *) NULL,
  106.    (struct Gadget *) NULL    /* pointer to extra gadgets */
  107. };
  108.  
  109. /***************************************************************************
  110.  *
  111.  * Open the Libraries and custom screen
  112.  *
  113.  **************************************************************************/
  114.  
  115. /*
  116.  * Open the libraries
  117.  */
  118. int
  119. OpenLibs() {
  120.  
  121.   ExecBase = (struct ExecBase *) OpenLibrary( ExecLib, (long) 0);
  122.  
  123.   if (ExecBase == NULL) {
  124.      LibErr( ExecLib );
  125.      return( 100);
  126.      }
  127.  
  128. #define LIB_FOR_1_2 33L
  129.   IntuitionBase = (struct IntuitionBase *) OpenLibrary( IntuiLib,
  130.                   LIB_FOR_1_2);
  131.  
  132.   if (IntuitionBase == NULL) {
  133.      LibErr( IntuiLib );
  134.      return(100);
  135.      }
  136.  
  137.   GfxBase = (struct GfxBase *) OpenLibrary( GfxLib, (long) 0);
  138.  
  139.   if (GfxBase == NULL) {
  140.      LibErr( GfxLib );
  141.      return(100);
  142.      }
  143.  
  144.   LayersBase = (struct LayersBase *) OpenLibrary( LayersLib, (long) 0);
  145.  
  146.   if (LayersBase == NULL) {
  147.      LibErr( LayersLib );
  148.      return(100);
  149.      }
  150.  
  151.   MathIeeeDoubBasBase = (struct MathIeeeDoubBasBase *)
  152.      OpenLibrary( IEEELib, (long) 0);
  153.  
  154.   if (MathIeeeDoubBasBase == NULL) {
  155.      LibErr( IEEELib );
  156.      return(100);
  157.      }
  158.  
  159.   /* if started from the workbench, then open the icon library */
  160.  
  161.   if (FromWB) {
  162.  
  163.     IconBase = (struct IconBase *) OpenLibrary( IconLib, (long) 0);
  164.  
  165.     if (IconBase == NULL) {
  166.        LibErr( IconLib );
  167.        return(100);
  168.        }
  169.   }
  170.  
  171.   return(0);
  172. } /* OpenLibs */
  173.  
  174. OpenFFPLibs()
  175. {
  176.   if ( MathBase == NULL ) {
  177.  
  178.     MathBase = (struct MathBase *) OpenLibrary( FFPLib, (long) 0);
  179.  
  180.     if (MathBase == NULL) {
  181.        DispErrMsg( "Can't open FFP library", 0);
  182.        return(100);
  183.     }
  184.   }
  185.  
  186.   if ( MathTransBase == NULL ) {
  187.  
  188.     MathTransBase = (struct MathTransBase *)
  189.                     OpenLibrary( TransLib, (long) 0);
  190.  
  191.     if (MathTransBase == NULL) {
  192.        DispErrMsg( "Can't open FFP transcendental library", 0);
  193.        return(100);
  194.     }
  195.   }
  196.   return(0);
  197. }
  198.  
  199. LibErr( Name )
  200.   char *Name;
  201. {
  202.   printf("Can't open %s\nPlease check to see if it is present on your disk\n",Name);
  203. }
  204.  
  205. /*
  206.  * Close the libraries used
  207.  */
  208. CloseLibs() {
  209.  
  210.   if ( MathBase )
  211.     CloseLibrary( MathBase );
  212.   MathBase = NULL;
  213.  
  214.   if ( MathTransBase )
  215.     CloseLibrary( MathTransBase );
  216.   MathTransBase = NULL;
  217.  
  218.   if ( MathIeeeDoubBasBase )
  219.     CloseLibrary( MathIeeeDoubBasBase );
  220.   MathIeeeDoubBasBase = NULL;
  221.  
  222.   if ( IconBase )
  223.     CloseLibrary( IconBase );
  224.   IconBase = NULL;
  225.  
  226.   if ( IntuitionBase )
  227.     CloseLibrary( IntuitionBase );
  228.   IntuitionBase = NULL;
  229.  
  230.   if ( LayersBase )
  231.     CloseLibrary( LayersBase );
  232.   LayersBase = NULL;
  233.  
  234.   if ( GfxBase )
  235.     CloseLibrary( GfxBase );
  236.   GfxBase = NULL;
  237.  
  238.   if ( ExecBase )
  239.     CloseLibrary( ExecBase );
  240.   ExecBase = NULL;
  241.  
  242. } /* CloseLibs */
  243.  
  244. struct Window *Save_PR_Wind;
  245.  
  246. /*
  247.  * Open the display
  248.  */
  249. int
  250. OpenDisp()
  251. {
  252.   extern UBYTE ContOpen, PaletteOpen, CycleOpen, HistOpen;
  253.  
  254.   extern struct MenuItem GenerateSubs[];
  255.  
  256.   NewScreenSize( &NewScreen );
  257.  
  258.   if (NewScreen.ViewModes & HIRES) {
  259.     XScale = 1;
  260.   } else {
  261.     XScale = 0;
  262.   }
  263.  
  264.   if (NewScreen.ViewModes & INTERLACE) {
  265.     YScale = 1;
  266.   } else {
  267.     YScale = 0;
  268.   }
  269.  
  270.   RightMarg = 16;
  271.  
  272.   screen = OpenScreen( (struct NewScreen *) &NewScreen);
  273.  
  274.   if (screen == NULL) {
  275.      AndDie("Can't open new screen!\n");
  276.   }
  277.   vp = &screen->ViewPort;
  278.  
  279.   Num_vp_Colors = 1 << NewScreen.Depth;
  280.  
  281.   if (Num_vp_Colors > 32)
  282.     Num_vp_Colors = 32;
  283.  
  284.   if (CurPict)
  285.     LoadRGB4(vp, CurPict->RGBs, Num_vp_Colors );
  286.   else
  287.     DefaultColors();
  288.  
  289.   if ( ExecBase->AttnFlags & AFF_68020 ) {
  290.     GenerateSubs[ INTIIGENERATOR ].Flags |= ITEMENABLED;
  291.   }
  292.  
  293.   if ( ExecBase->AttnFlags & AFF_68881 ) {
  294.     GenerateSubs[ _81GENERATOR ].Flags |= ITEMENABLED;
  295.   }
  296.  
  297.   InitViewModesSubs();
  298.   InitDepthSubs();
  299.   InitGenSubs();
  300.  
  301.   AllocateMice();
  302.  
  303.   OpenBackWind();      /* Open this before any other window */
  304.  
  305.   Save_PR_Wind = (struct Window *)
  306.                  ((struct Process *) FindTask(0L))->pr_WindowPtr;
  307.  
  308.   ((struct Process *) FindTask(0L))->pr_WindowPtr = (APTR) BackWind;
  309.  
  310.   ReOpenPicts();
  311.  
  312.   if (ContOpen)    OpenContWind();
  313.   if (HistOpen)    OpenHistWind();
  314.   if (PaletteOpen) OpenPalWind();
  315.   if (CycleOpen)   OpenCycWind();
  316.  
  317.   return(0);
  318. } /* opendisp */
  319.  
  320. /*
  321.  *  Close the screen
  322.  */
  323. CloseDisp() {
  324.  
  325.   if ( screen ) {
  326.  
  327.     CloseCycWind();
  328.     ClosePalWind();
  329.     CloseContWind();
  330.     CloseHistWind();
  331.     CloseStatsWind();
  332.     CloseOrbitWind();
  333.  
  334.     CloseHelpWind(0,NULL);
  335.  
  336.     ClosePicts();
  337.  
  338.     CloseBackWind();   /* Close this window last */
  339.  
  340.     ((struct Process *) FindTask(0L))->pr_WindowPtr = (APTR) Save_PR_Wind;
  341.  
  342.     NewScreen.TopEdge = screen->TopEdge >> YScale;
  343.  
  344.     CloseScreen( screen );
  345.  
  346.     screen = NULL;
  347.  
  348.     FreeMice();
  349.   }
  350. } /* CloseDisp */
  351.  
  352. /*
  353.  * Check New Screen Size
  354.  */
  355. int
  356. NewScreenSize( NewScreen )
  357.   struct NewScreen *NewScreen;
  358. {
  359.   extern struct MenuItem ScreenSizeSubs[];
  360.  
  361.   struct Screen WBenchScreen;
  362.  
  363.   (void) GetScreenData( &WBenchScreen, sizeof(struct Screen),
  364.                          WBENCHSCREEN, NULL);
  365.  
  366.   if (!(WBenchScreen.ViewPort.Modes & LACE)) {
  367.     WBenchScreen.Height <<= 1;
  368.   }
  369.  
  370.   if ( StandardSize ) {
  371.  
  372.     WBenchScreen.Width  = 640;
  373.  
  374.     if (GfxBase->DisplayFlags & PAL)
  375.       WBenchScreen.Height = 512;
  376.     else
  377.       WBenchScreen.Height = 400;
  378.   }
  379.  
  380.   if (NewScreen->ViewModes & HIRES) {
  381.  
  382.     if ( NewScreen->Depth > 4 )
  383.       NewScreen->Depth = 4;
  384.  
  385.     if ( NewScreen->ViewModes & EXTRA_HALFBRITE )
  386.       NewScreen->ViewModes &= ~EXTRA_HALFBRITE;
  387.  
  388.     NewScreen->Width = WBenchScreen.Width;
  389.  
  390.   } else {
  391.  
  392.     NewScreen->Width = WBenchScreen.Width >> 1;
  393.   }
  394.  
  395.   if (NewScreen->ViewModes & INTERLACE) {
  396.  
  397.     NewScreen->Height = WBenchScreen.Height;
  398.   } else {
  399.  
  400.     NewScreen->Height = WBenchScreen.Height >> 1;
  401.   }
  402.  
  403.   if (NewScreen->ViewModes & EXTRA_HALFBRITE) {
  404.  
  405.     NewScreen->Depth = 6;
  406.   } else {
  407.  
  408.     if (NewScreen->Depth == 6)
  409.       NewScreen->Depth = 5;
  410.   }
  411.  
  412.   NewScreen->TopEdge <<= YScale;
  413. } /* NewScreenSize */
  414.  
  415. SaveRGBs( Pict )
  416.   struct Picture *Pict;
  417. {
  418.   register int i;
  419.   register SHORT *RGBs;
  420.  
  421.   if (Pict) {
  422.  
  423.     RGBs = Pict->RGBs;
  424.  
  425.     for (i = 0; i < Num_vp_Colors; i++)
  426.       *RGBs++ = GetRGB4(vp->ColorMap, i);
  427.   }
  428. }
  429.  
  430. AndDie( ErrMsg )
  431.   char *ErrMsg;
  432. {
  433.   printf("%s\n", ErrMsg);
  434.  
  435.   ThrowPicts();
  436.  
  437.   CloseTasks();
  438.   CloseDisp();
  439.   CloseLibs();
  440.  
  441.   exit(0);
  442. }
  443.  
  444. OpenBackWind()
  445. {
  446.   NewBack.Screen = screen;
  447.   NewBack.Width  = screen->Width;
  448.   NewBack.Height = screen->Height - NewBack.TopEdge - 1;
  449.  
  450.   BackWind = OpenWindow( &NewBack );
  451.  
  452.   if ( BackWind == NULL ) {
  453.     AndDie("Can't open common window\n");
  454.   }
  455.  
  456.   (void) SetMenuStrip( BackWind, Menu );
  457.  
  458.   CurWind = BackWind;
  459.  
  460.   ForceNormPointer();
  461. }
  462.  
  463. CloseBackWind()
  464. {
  465.   ClearPointer( BackWind );
  466.  
  467.   ClearMenuStrip( BackWind );
  468.  
  469.   CloseWindow( BackWind );
  470.   BackWind = NULL;
  471. }
  472.  
  473. /***************************************************************************
  474.  *
  475.  * Open and Close Window tools
  476.  *
  477.  **************************************************************************/
  478.  
  479. int NumWindows;
  480.  
  481. /*
  482.  *  Open a window and put it in the window list
  483.  */
  484. struct Window *OpenMyWind(NewWind, Screen, Gadgets, Width, Height)
  485.   struct NewWindow *NewWind;
  486.   struct Screen *Screen;
  487.   struct Gadget *Gadgets;
  488.   SHORT  Width, Height;
  489. {
  490.   register struct Window *Window;
  491.   register LONG t;
  492.  
  493.   NewWind->Screen = Screen;
  494.   NewWind->FirstGadget = Gadgets;
  495.  
  496.   NewWind->Width = Width;
  497.   NewWind->Height = Height;
  498.  
  499.   /* Window too wide ? */
  500.  
  501.   t = Width - Screen->Width;
  502.  
  503.   if (t > 0) {
  504.     Width -= t;
  505.   }
  506.  
  507.   /* Too far to the right ? */
  508.  
  509.   t = NewWind->LeftEdge + Width - Screen->Width;
  510.  
  511.   if ( t > 0 ) {
  512.     NewWind->LeftEdge -= t;
  513.   }
  514.  
  515.   /* Window too tall ? */
  516.  
  517.   t = Height - Screen->Height;
  518.  
  519.   if (t > 0) {
  520.     Height -= t;
  521.   }
  522.  
  523.   /* Too close to the bottom ? */
  524.  
  525.   t = NewWind->TopEdge + Height - Screen->Height;
  526.  
  527.   if ( t > 0 ) {
  528.     NewWind->TopEdge -= t;
  529.   }
  530.  
  531.   Window = OpenWindow( NewWind );
  532.  
  533.   if (Window == (struct Window *) NULL) {
  534.     DispErrMsg("Can't open new window",0);
  535.     return( (struct Window *) NULL);
  536.   }
  537.  
  538.   Window->UserPort = BackWind->UserPort;
  539.   ModifyIDCMP( Window, (long) BackWind->IDCMPFlags );
  540.  
  541.   Window->UserData = NULL;
  542.  
  543.   (void) SetMenuStrip(Window, Menu);
  544.  
  545.   CurWind = Window;
  546.  
  547.   ForceNormPointer();
  548.  
  549.   return(Window);
  550. } /* OpenMyWind */
  551.  
  552. /*
  553.  * Deallocate all the gadgets associated with this window
  554.  * Close the window
  555.  */
  556. CloseMyWind(Window,Gadgets)
  557.   struct Window *Window;
  558.   struct Gadget *Gadgets;
  559. {
  560.   if (Window) {
  561.  
  562.      /* get rid of the menu */
  563.      if (Window->MenuStrip)
  564.        ClearMenuStrip(Window);
  565.  
  566.      /* get rid of the pointer */
  567.      if (Window->Pointer)
  568.        ClearPointer( Window );
  569.  
  570.      if ( Window == CurWind ) {
  571.        CurWind = BackWind;
  572.      }
  573.  
  574.      CloseWindowSafely( Window );
  575.  
  576.      if (Gadgets)
  577.        FreeGadgets(Gadgets);
  578.   }
  579. } /* CloseMyWind */
  580.  
  581. /***************************************************************************
  582.  *
  583.  * This section handles the Mouse pointer for the custom screen
  584.  *
  585.  **************************************************************************/
  586.  
  587. USHORT *BabyBrotPointer;
  588. USHORT *BabyToPointer;
  589. USHORT *BabyWithPointer;
  590. USHORT *SleepyPointer;
  591.  
  592. /***************************************************************/
  593. /*  This is the image for baby Mandelbrot pointer              */
  594. /***************************************************************/
  595.  
  596. USHORT BabyBrotSprite[]=  {
  597.  0x0000, 0x0000,
  598.  0x8000, 0x0000,
  599.  0x5000, 0x5000,
  600.  0x2202, 0x2202,
  601.  0x4D82, 0x5F82,
  602.  0x0013, 0x1913,
  603.  0x006C, 0x11FE,
  604.  0x2000, 0x300A,
  605.  0x0C00, 0x1C06,
  606.  0x1004, 0x1407,
  607.  0x0004, 0x0404,
  608.  0x0028, 0x042C,
  609.  0x0800, 0x0C1C,
  610.  0x0220, 0x0630,
  611.  0x01C0, 0x05F0,
  612.  0x3800, 0x3F80,
  613.  0x0000, 0x0880,
  614.  0x0000, 0x0000,
  615.  };
  616.  
  617. /***************************************************************/
  618. /*  This is a baby brot pointer with 'TO' in it.               */
  619. /***************************************************************/
  620. USHORT BabyToSprite[]=  {
  621.  0x0000, 0x0000,
  622.  0x8000, 0x0000,
  623.  0x5000, 0x5000,
  624.  0x2202, 0x2202,
  625.  0x4D82, 0x5F82,
  626.  0x0013, 0x1913,
  627.  0x006C, 0x11FE,
  628.  0x2000, 0x300A,
  629.  0x0C00, 0x1C06,
  630.  0x1004, 0x1407,
  631.  0x0004, 0x0404,
  632.  0x0028, 0x042C,
  633.  0x0800, 0x0C1C,
  634.  0x0220, 0x0630,
  635.  0x01C0, 0x05F0,
  636.  0x3800, 0x3F80,
  637.  0x0000, 0x0880,
  638.  0x0000, 0x0000,
  639.  0x3F00, 0x3F00,
  640.  0x2D00, 0x3F80,
  641.  0x0C78, 0x1EF8,
  642.  0x0CCC, 0x0EFC,
  643.  0x0CCC, 0x0EEE,
  644.  0x0CCC, 0x0EEE,
  645.  0x1E78, 0x1E7E,
  646.  0x0000, 0x0F3C,
  647.  0x0000, 0x0000,
  648.  };
  649.  
  650. /***************************************************************/
  651. /*  This is a baby brot pointer with 'WITH' in it.             */
  652. /***************************************************************/
  653. USHORT BabyWithSprite[]=  {
  654.  0x0000, 0x0000,
  655.  0x8000, 0x0000,
  656.  0x5000, 0x5000,
  657.  0x2202, 0x2202,
  658.  0x4D82, 0x5F82,
  659.  0x0013, 0x1913,
  660.  0x006C, 0x11FE,
  661.  0x2000, 0x300A,
  662.  0x0C00, 0x1C06,
  663.  0x1004, 0x1407,
  664.  0x0004, 0x0404,
  665.  0x0028, 0x042C,
  666.  0x0800, 0x0C1C,
  667.  0x0220, 0x0630,
  668.  0x01C0, 0x05F0,
  669.  0x3800, 0x3F80,
  670.  0x0000, 0x0880,
  671.  0x0000, 0x0000,
  672.  0x0630, 0x0630,
  673.  0x0630, 0x0738,
  674.  0x0630, 0x0738,
  675.  0x06B0, 0x07B8,
  676.  0x07F0, 0x07F8,
  677.  0x0770, 0x07F8,
  678.  0x0630, 0x07B8,
  679.  0x0000, 0x0318,
  680.  0x00C0, 0x00C0,
  681.  0x0000, 0x0060,
  682.  0x01C0, 0x01C0,
  683.  0x00C0, 0x00E0,
  684.  0x00C0, 0x00E0,
  685.  0x00C0, 0x00E0,
  686.  0x01E0, 0x01E0,
  687.  0x0000, 0x00F0,
  688.  0x0000, 0x0000,
  689.  0x0040, 0x0040,
  690.  0x00C0, 0x00E0,
  691.  0x01F0, 0x01F0,
  692.  0x00C0, 0x00F8,
  693.  0x00C0, 0x00E0,
  694.  0x00D0, 0x00F0,
  695.  0x0060, 0x0068,
  696.  0x0700, 0x0730,
  697.  0x0300, 0x0380,
  698.  0x0360, 0x03E0,
  699.  0x03B0, 0x03B0,
  700.  0x0330, 0x03F8,
  701.  0x0330, 0x03B8,
  702.  0x0730, 0x07B8,
  703.  0x0000, 0x0398,
  704.  0x0000, 0x0000,
  705.  };
  706.  
  707. /***************************************************************/
  708. /*  This is a sleepy cloud pointer                             */
  709. /***************************************************************/
  710. USHORT SleepySprite[] = {
  711.       0x0000,  0x0000,
  712.       0x0fe0,  0x0000,
  713.       0x1830,  0x07c0,
  714.       0x7018,  0x0fe0,
  715.       0xc008,  0x3ff0,
  716.       0x9e0c,  0x7ff0,
  717.       0x8406,  0x7ff8,
  718.       0x8802,  0x7ffc,
  719.       0x1e03,  0xfffc,
  720.       0x80f1,  0x7ffe,
  721.       0x8021,  0x7ffe,
  722.       0x4040,  0x3fff,
  723.       0x80f1,  0x7ffe,
  724.       0xc001,  0x3ffe,
  725.       0x6003,  0x1ffc,
  726.       0x3006,  0x0ff8,
  727.       0x180c,  0x07f0,
  728.       0x0718,  0x00e0,
  729.       0x0070,  0x0f80,
  730.       0x1810,  0x07e0,
  731.       0x0820,  0x0740,
  732.       0x0ff0,  0x0000,
  733.       0x0020,  0x03c0,
  734.       0x0410,  0x03e0,
  735.       0x0310,  0x00e0,
  736.       0x00e0,  0x0000,
  737.       0x0000,  0x0000,
  738.      };
  739.  
  740. /* pointer types  */
  741. #define UNINITIALIZED 0
  742. #define NORMPOINTER   1
  743. #define TOPOINTER     2
  744. #define WITHPOINTER   3
  745. #define SLEEPYPOINTER 4
  746.  
  747. UBYTE   PointerType = UNINITIALIZED;
  748.  
  749. /* defines for the cute pointer sprite */
  750. #define MYSPRITE_WIDTH    ((long) 16)
  751. #define MYSPRITE_HEIGHT   ((long) 16)
  752. #define TOSPRITE_WIDTH    ((long) 16)
  753. #define TOSPRITE_HEIGHT   ((long) 25)
  754. #define WITHSPRITE_WIDTH  ((long) 16)
  755. #define WITHSPRITE_HEIGHT ((long) 50)
  756. #define SLEEPY_WIDTH      ((long) 16)
  757. #define SLEEPY_HEIGHT     ((long) 25)
  758. #define MYSPRITE_HOTX     ((long) -1)
  759. #define MYSPRITE_HOTY     ((long)  0)
  760.  
  761. #define BABYSIZE   ((int) ((MYSPRITE_HEIGHT   + 2) * 8))
  762. #define TOSIZE     ((int) ((TOSPRITE_HEIGHT   + 2) * 8))
  763. #define WITHSIZE   ((int) ((WITHSPRITE_HEIGHT + 2) * 8))
  764. #define SLEEPYSIZE ((int) ((SLEEPY_HEIGHT     + 2) * 8))
  765.  
  766. /*
  767.  * Copy an Image into a chip ram image
  768.  */
  769. USHORT *
  770. MakeChipSprite( FastRamSprite, Size )
  771.   register USHORT *FastRamSprite;
  772.   register int    Size;
  773. {
  774.   register USHORT *ChipSprite, *SaveSprite;
  775.   register int i;
  776.  
  777.   ChipSprite = (USHORT *)
  778.                safeAllocMem( (ULONG) (Size * sizeof(SHORT)), MEMF_CHIP );
  779.  
  780.   if ( ChipSprite == NULL )
  781.     return ( ChipSprite );
  782.  
  783.   SaveSprite = ChipSprite;
  784.  
  785.   for ( i = 0; i < Size; i++)
  786.     *(ChipSprite++) = *(FastRamSprite++);
  787.  
  788.   return( SaveSprite );
  789. }
  790.  
  791. /*
  792.  * Allocate all the mouse pointer sprites used by this program
  793.  */
  794. AllocateMice()
  795. {
  796.   BabyBrotPointer = MakeChipSprite( BabyBrotSprite, BABYSIZE );
  797.   BabyToPointer   = MakeChipSprite( BabyToSprite,   TOSIZE );
  798.   BabyWithPointer = MakeChipSprite( BabyWithSprite, WITHSIZE );
  799.   SleepyPointer   = MakeChipSprite( SleepySprite,   SLEEPYSIZE );
  800. }
  801.  
  802. /*
  803.  * Free all the mouse pointer sprites used by this program
  804.  */
  805. FreeMice()
  806. {
  807.   if ( BabyBrotPointer )
  808.     FreeMem( (char *) BabyBrotPointer, (long) BABYSIZE * sizeof(SHORT) );
  809.   BabyBrotPointer = NULL;
  810.  
  811.   if ( BabyToPointer )
  812.     FreeMem( (char *) BabyToPointer, (long) TOSIZE * sizeof(SHORT) );
  813.   BabyToPointer = NULL;
  814.  
  815.   if ( BabyWithPointer )
  816.     FreeMem( (char *) BabyWithPointer, (long) WITHSIZE * sizeof(SHORT) );
  817.   BabyWithPointer = NULL;
  818.  
  819.   if ( SleepyPointer )
  820.     FreeMem( (char *) SleepyPointer, (long) SLEEPYSIZE * sizeof(SHORT) );
  821.   SleepyPointer = NULL;
  822. }
  823.  
  824.  
  825. /*
  826.  * Set all window pointers NewPointer
  827.  */
  828. SetPointers()
  829. {
  830.   SetMouse( CurWind );
  831. }
  832.  
  833. /*
  834.  * Force normal pointers
  835.  */
  836. ForceNormPointer()
  837. {
  838.   PointerType = UNINITIALIZED;
  839.  
  840.   SetNormPointer();
  841. }
  842.  
  843. /*
  844.  * Set Normal Mouse Pointer
  845.  */
  846. SetNormPointer()
  847. {
  848.   if (PointerType != NORMPOINTER ) {
  849.  
  850.     PointerType = NORMPOINTER;
  851.  
  852.     SetPointers();
  853.   }
  854. }
  855.  
  856. /*
  857.  * Set 'To' Mouse Pointer
  858.  */
  859. SetToPointer()
  860. {
  861.   if (PointerType != TOPOINTER ) {
  862.  
  863.     PointerType = TOPOINTER;
  864.  
  865.     SetPointers();
  866.   }
  867. }
  868.  
  869. /*
  870.  * Set 'With' Mouse Pointer
  871.  */
  872. SetWithPointer()
  873. {
  874.   if (PointerType != TOPOINTER ) {
  875.  
  876.     PointerType = WITHPOINTER;
  877.  
  878.     SetPointers();
  879.   }
  880. }
  881.  
  882. /*
  883.  * Set Sleepy Mouse Pointer
  884.  */
  885. SetSleepyPointer()
  886. {
  887.   if (PointerType != SLEEPYPOINTER ) {
  888.  
  889.     PointerType = SLEEPYPOINTER;
  890.  
  891.     SetPointers();
  892.   }
  893. }
  894.  
  895. SetMouse( window )
  896.   struct Window *window;
  897. {
  898.   if (window == NULL)
  899.     return;
  900.  
  901.   switch ( PointerType ) {
  902.  
  903.     case   NORMPOINTER:
  904.            SetPointer( window,          BabyBrotPointer,
  905.                        MYSPRITE_HEIGHT, MYSPRITE_WIDTH,
  906.                        MYSPRITE_HOTX,   MYSPRITE_HOTY);
  907.            break;
  908.  
  909.     case   TOPOINTER:
  910.            SetPointer( window,          BabyToPointer,
  911.                        TOSPRITE_HEIGHT, TOSPRITE_WIDTH,
  912.                        MYSPRITE_HOTX,   MYSPRITE_HOTY);
  913.            break;
  914.  
  915.     case   WITHPOINTER:
  916.            SetPointer( window,            BabyWithPointer,
  917.                        WITHSPRITE_HEIGHT, WITHSPRITE_WIDTH,
  918.                        MYSPRITE_HOTX,     MYSPRITE_HOTY);
  919.            break;
  920.  
  921.     case   SLEEPYPOINTER:
  922.            SetPointer( window,          SleepyPointer,
  923.                        SLEEPY_HEIGHT,   SLEEPY_WIDTH,
  924.                        MYSPRITE_HOTX,   MYSPRITE_HOTY);
  925.            break;
  926.   }
  927. }
  928.  
  929. /**************************************************************************
  930.  *
  931.  *  This code is used to display error messages on the cusom screen
  932.  *
  933.  **************************************************************************/
  934. struct IntuiText msg_txt =
  935.    {
  936.      0,
  937.      1,
  938.      JAM2,
  939.      5,
  940.      20,
  941.      NULL,
  942.      NULL,
  943.      NULL
  944.    };
  945.  
  946. struct IntuiText OK_txt =
  947.    {
  948.      0,
  949.      1,
  950.      JAM2,
  951.      5,
  952.      3,
  953.      NULL,
  954.      (UBYTE *) "YES",
  955.      NULL
  956.    };
  957.  
  958. struct IntuiText NO_txt =
  959.    {
  960.      0,
  961.      1,
  962.      JAM2,
  963.      5,
  964.      3,
  965.      NULL,
  966.      (UBYTE *) "NO",
  967.      NULL
  968.    };
  969.  
  970. struct IntuiText Cont_txt =
  971.    {
  972.      0,
  973.      1,
  974.      JAM2,
  975.      5,
  976.      3,
  977.      NULL,
  978.      (UBYTE *) "Continue",
  979.      NULL
  980.    };
  981.  
  982.  
  983. DispErrMsg(ErrMsg, Flag)
  984.   char *ErrMsg;
  985.   SHORT  Flag;
  986. {
  987.   msg_txt.IText = (UBYTE *) ErrMsg;
  988.  
  989.   SetNormPointer();
  990.  
  991.   if (BackWind) {
  992.  
  993.     if (Flag) {
  994.  
  995.       return( AutoRequest(BackWind, &msg_txt, &OK_txt, &NO_txt, 0L, 0L,
  996.              (long) (IntuiTextLength(&msg_txt) + 50L), 70L));
  997.     } else {
  998.  
  999.       (void) AutoRequest(BackWind, &msg_txt, 0L, &Cont_txt, 0L, 0L,
  1000.              (long) (IntuiTextLength(&msg_txt) + 50L), 70L);
  1001.     }
  1002.  
  1003.   } else {
  1004.     if (FromWB)
  1005.       printf("%s\n", ErrMsg);
  1006.   }
  1007.   return(0);
  1008. }
  1009.  
  1010. #define _K (1024L)
  1011. #define LOW_MEM_MARK (30*_K)
  1012.  
  1013. #ifdef MEM_DEBUG
  1014.  
  1015. APTR
  1016. SafeAllocMem( size, flags )
  1017.  
  1018. #else
  1019.  
  1020. APTR
  1021. safeAllocMem( size, flags )
  1022.  
  1023. #endif
  1024.  
  1025.   ULONG size;
  1026.   ULONG flags;
  1027. {
  1028.   register APTR p;
  1029.  
  1030.   if ( p = (APTR) AllocMem( (long) size, (long) flags) )
  1031.     if ( AvailMem( (long) flags ) < LOW_MEM_MARK ) {
  1032.       FreeMem((char *) p, (long) size);
  1033.       return( NULL );
  1034.     }
  1035.   return( p );
  1036. }
  1037.  
  1038.